package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 创建日期: 2022-01-19-20-02
 * author : XGQ
 * description: 主页显示接口
 */
@RestController
@RequestMapping("shopping")
public class HomepageController {

    @Reference(timeout = 10000,retries = 0,check = false)
    IHomeService homeService;

    @GetMapping("homepage")
    @Anoymous
    // 返回值规范
    public ResponseData getShowHomepage(){
        // 调用接口,返回response
        HomePageResponse response = homeService.homepage();
        // 判断状态码是否ok
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            // 返回一个包含商品数据的ResponseData对象
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        // 返回一个错误的商品数据的ResponseData对象
        return new ResponseUtil().setErrorMsg(response.getMsg());

    }
}
